package edu.neelsys.objectmodel.userauth;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import edu.neelsys.objectmodel.dbentites.User;

public class LoggedUser implements UserDetails {

	User user;

	/**
	 * @param user
	 */
	public LoggedUser(User user) {
		this.user = user;
	}

	public User getUser() {
		return user;
	}

	@Override
	public Collection<? extends GrantedAuthority> getAuthorities() {

		LoggedUserRole loggedUserRole = new LoggedUserRole(user.getUserRole());

		List<LoggedUserRole> roleList = new ArrayList<>();
		roleList.add(loggedUserRole);

		return roleList;
	}

	@Override
	public String getPassword() {
		return user.getPassword();
	}

	@Override
	public String getUsername() {
		return user.getUserName();
	}

	@Override
	public boolean isAccountNonExpired() {
		return true;
	}

	@Override
	public boolean isAccountNonLocked() {
		return true;
	}

	@Override
	public boolean isCredentialsNonExpired() {
		return true;
	}

	@Override
	public boolean isEnabled() {
		return true;
	}

}
